/*
 * @Descripttion:
 * @version:
 * @Author: kl2018
 * @Date: 2020-05-28 15:51:33
 * @LastEditors: kl2018
 * @LastEditTime: 2020-06-22 10:53:19
 */
import React, { Component } from 'react';
import { WeaLocaleProvider, WeaTools, WeaErrorPage } from 'ecCom';
import '../../../style/signInput.less';
import objectAssign from 'object-assign';

const { getLabel } = WeaLocaleProvider;

class OdocSignInput extends Component {
	constructor(props) {
		super(props);
		this.state = {
			hasLoad: false,
		};
	}

	componentDidMount() {
		const init = () => {
			this.setState({ hasLoad: true });
		};
		window.eventRegister && window.eventRegister.loadModule('workfolwPublic', init);
	}

	componentDidUpdate() {
		const { hasLoad } = this.state;
		if (hasLoad) {
			const { coreparams } = this.props;
			const { refid = (new Date().getTime()) } = coreparams;
			let refidedit = `${refid}Edit`;
			window[`REMARK_CK_REF${refidedit}`] = this.refs[refid];

			/* if (typeof window["REMARK_CK_REF"+refidedit] === "undefined") {
			} */
		}
	}

	render() {
		const { hasLoad } = this.state;
		let content = <div />;
		if (hasLoad) {
			const { WfSignInput } = window.weaWorkflowPublic;
			const { workflowStores, coreparams } = this.props;
			const { signInputRequired = false, refid = (new Date().getTime()), premarkinfo = {} } = coreparams;
			const { globalStore = {} } = workflowStores;
			let { commonParam = {}, markInfo = {}, loadMarkInfo } = globalStore;
			markInfo = objectAssign({ remarkInfo: { handWrittenSignSwitch: -1 } }, markInfo, premarkinfo);
			const { requestid, requestType } = commonParam;
			let { remarkInfo = {} } = markInfo;

			content = (<div>
				<div className={'OdocSignInputTitle'}>
					<i className="icon-coms-Need-feedback" />
					<span>{getLabel(17614, '签字意见')}</span>
					{signInputRequired && (<span className={'signInputRequired'}> ({getLabel(18019, '必填')})</span>)}
				</div>
				<WfSignInput ecId={`${this && this.props && this.props.ecId || ''}_WfSignInput@91k91x`}
  ref={refid}
  markInfo={markInfo}
  requestType={requestType}
  requestid={requestid}
  isShowSignInput={true}
  editorId={`${refid}Edit`}
  maxHeight={150}
  {...remarkInfo}
  changeRemarkInfo={this.changeRemarkInfo}
  onChange={this.onChange}
  saveCallBack={loadMarkInfo}
				/>
			</div>);
		}
		return (
			content
		);
	}

	onChange = (params = {}) => {
		const { allFunction = {} } = this.props;
		const { changecallback } = allFunction;
		typeof changecallback == 'function' && changecallback(params);
	}

	changeRemarkInfo = (params = {}) => {
		const { workflowStores = {}, allFunction = {} } = this.props;
		const { changecallback } = allFunction;
		const { globalStore = {} } = workflowStores;
		const { changeSubmitParam } = globalStore;
		typeof changeSubmitParam == 'function' && changeSubmitParam(params);
		typeof changecallback == 'function' && changecallback(params);
	}
}

export default WeaTools.tryCatch(React,
	props => <WeaErrorPage ecId={`${this && this.props && this.props.ecId || ''}_WeaErrorPage@77jm38`} msg={props.error ? props.error : getLabel(385218, '对不起，该页面异常，请联系管理员！')} />,
	{ error: '' },
)(OdocSignInput);
